package com.xaut.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.HttpServletBean;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
@RequestMapping("/sxy")
public class ControllerDemo {

    /**
     * 开发实现的的Handler即Controller层方法
     * @return
     */
    @RequestMapping(value = "/xaut",method = {RequestMethod.POST,RequestMethod.GET} )
    public String tulun(HttpServletRequest request, HttpServletResponse response, HttpSession session,
                         Model model) {
        String id = (String)request.getAttribute("id");
        try {
            response.getWriter().write("收到id！");
        } catch (IOException e) {
            e.printStackTrace();
        }
//        返回的ModelAndView
//        返回指定的页面
        return "index";
    }

    @RequestMapping(value = "/test",method = {RequestMethod.GET})
    public String test() {
//        返回的ModelAndView
//        返回指定的页面
        return "index";
    }

    @RequestMapping("/baseDataType")
    public String baseDataType(@RequestParam("userName") String userName,
                               @RequestParam("userPassword") String userPassword) {
        System.out.println("数据userName："+userName);
        System.out.println("数据userPassword："+userPassword);

        //return "index";
        return "success";
    }
}